<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activIds']))
{
	header("Location:checkLogin.php");
}
else
{
  $processArrayList = array();
  $k=0;
  $maxStageNo = 0;
  $selectprocessList = "SELECT stagecontract.invoiceId,MAX(stageprocess.stageProcessId) AS stageProcessId,action,
                               invoiceNo,stageProcessName 
                          FROM stagecontract
                          LEFT JOIN invoice ON invoice.invoiceId = stagecontract.invoiceId
                          LEFT JOIN stageprocess ON stageprocess.stageProcessId = stagecontract .stageProcessId
  	                      WHERE action='C'
  	                      AND stagecontract.invoiceId = ".$_REQUEST['invoiceId'];
  $selectprocessListRes = mysql_query($selectprocessList);
  while($processListRow = mysql_fetch_array($selectprocessListRes))
  {
   	$maxStageNo                                 =($processListRow['stageProcessId'] == '')? 0:$processListRow['stageProcessId'];
    $processArrayList[$k]['stageProcessName']   = $processListRow['stageProcessName'];
  	$processArrayList[$k]['invoiceNo']          = $processListRow['invoiceNo'];
  	$processArrayList[$k]['action']             = $processListRow['action'];
  	$k++;
  }
  
  $allProcessArrayList = array();
  $k=0;
  $selectAllProcessList = "SELECT stagecontract.stageProcessId,stageProcessName
  	                      FROM stagecontract
  	                      LEFT JOIN stageProcess ON stageProcess.stageProcessId = stagecontract .stageProcessId";
  $selectAllProcessListRes = mysql_query($selectAllProcessList);
  while($allProcessListRow = mysql_fetch_array($selectAllProcessListRes))
  {
  	$allProcessArrayList[$k]['stageProcessId']    = $allProcessListRow['stageProcessId'];
    $allProcessArrayList[$k]['stageProcessName']   = $allProcessListRow['stageProcessName'];
  	$k++;
  }
  
}
include("bottom.php");
$smarty->assign('maxStageNo',$maxStageNo);
$smarty->assign('processArrayList',$processArrayList);
$smarty->assign('allProcessArrayList',$allProcessArrayList);
$smarty->display("stageProcessStatus.tpl");
?>